package com.example.chapter3_1.dao;

import com.example.chapter3_1.entity.Card;
import com.example.chapter3_1.entity.Student;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.One;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StudentMapper {
    @Result(property = "card",column = "no",
    one = @One(select = "com.rgzn.chapter3_1.dao.StudentMapper.getCardByNo"))
    @Select("select * from  tb_student where  name like concat('%',#{name}，'%')")
    List<Student> getUsersByName(String name);

    @Select("select * from card where cardNo = #{number}")
    Card getCardByNo(String number);

    @Select({
            "<script>",
            "select * from tb_student where 1=1",
            "<if test='name!=null'>",
            " and name = #{name}",
            "</if>",
            "<if test='no!=null'>",
            " and no = #{no}",
            "</if>",
            "</script>"
    })
    List<Student> getUsersByNameOrNumber(String name, String no);
}
